package com.medusa.aps.business.modules.security.mp.entity;

import cn.hutool.core.annotation.Alias;
import com.baomidou.mybatisplus.annotation.*;
import com.medusa.aps.business.model.BaseEntity;
import com.medusa.aps.business.model.constant.RegexPool;
import com.medusa.aps.business.model.enums.SourceEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Set;


/**
 * @author: xianhui.yu
 **/
@Data
@Accessors(chain = true)
@TableName("sys_user")
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity<User> {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 主键ID  groups:标识在更新的时候才能验证非空
     */
    @TableId(value = "id", type = IdType.AUTO)
    @Schema(description = "用户id")
    @Alias("主键id")
    private Long id;
    /**
     * 成员姓名
     */
    @TableField("username")
    @NotBlank(message = "员工姓名不能为空")
    @Length(max = 50, message = "员工姓名不能超过50个字符")
    @Schema(description = "员工姓名")
    @Alias("员工姓名")
    private String username;


    /**
     * 员工工号
     */
    @TableField("job_number")
    @Schema(description = "员工工号")
    @NotBlank(message = "员工工号不能为空")
    @Size(max = 20, message = "员工工号不能超过20个字符")
    @Pattern(regexp = RegexPool.ORDER_NO, message = "员工工号只支持数字、字母、符号")
    @Alias("员工工号")
    private String jobNumber;

    /**
     * 职位
     */
    @TableField("position")
    @Schema(description = "职位")
    @NotBlank(message = "职位不能为空")
    @Pattern(regexp = RegexPool.ONLY_CHINESE, message = "职位只能为汉字")
    @Size(max = 50, message = "职位不能超过50个字符")
    @Alias("职位")
    private String position;

    /**
     * 车间id
     */
    @TableField(value = "workshop_id", updateStrategy = FieldStrategy.ALWAYS)
    @Schema(description = "车间id")
    @Alias("车间id")
    private Integer workshopId;

    /**
     * 车间编码
     */
    @TableField(exist = false)
    @Schema(description = "车间")
    @Alias("车间")
    private String workshopCode;


    /**
     * 密文密码
     */
    @TableField("password")
    @Schema(description = "密文密码")
    private String password;

    /**
     * 明文密码
     */
    @TableField("plain_password")
    @Schema(description = "明文密码")
    private String plainPassword;


    /**
     * 手机号码
     */
    @TableField("phone")
    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式有误")
    @Schema(description = "手机号")
    @Alias("手机号")
    private String phone;

    /**
     * 邮箱
     */
    @TableField(value = "email", updateStrategy = FieldStrategy.ALWAYS)
    @Email(message = "邮箱格式不对")
    @Schema(description = "邮箱")
    @Alias("邮箱")
    private String email;

    /**
     * 盐值
     */
    @TableField("salt")
    @Schema(description = "盐值")
    private String salt;


    /**
     * 数据来源
     */
    @TableField(value = "data_source", updateStrategy = FieldStrategy.NEVER)
    @Schema(description = "数据来源")
    private SourceEnum dataSource;

    /**
     * 创建人
     */
    @TableField(value = "creator", fill = FieldFill.INSERT)
    @Schema(description = "创建人")
    private String creator;

    /**
     * 备注
     */
    @Alias("备注")
    @TableField(value = "remarks", updateStrategy = FieldStrategy.ALWAYS)
    @Schema(description = "备注")
    private String remarks;

    /**
     * token过期时间
     */
    @TableField(exist = false)
    private Long expireTime;

    /**
     * 角色
     */
    @Alias("角色")
    @TableField(exist = false)
    private List<String> roleNames;

    /**
     *
     */
    @Alias("车间名称")
    @TableField(exist = false)
    private String workshopName;
    /**
     * 角色id
     */
    @TableField(exist = false)
    private Set<Integer> roleIds;

    @Override
    public Serializable pkVal() {
        return this.id;
    }

}
